var playerNum = 1;
var playerIDtext = 'previewPLayer';
var playerID = playerIDtext + playerNum;
var playerHTMLbegin = '<div class = "videoPreviewDiv"><video id="';
var playerHTMLend = '" class="video-js vjs-default-skin" preload="auto" width="124" height="80" data-setup="{}"> <source src="" type="video/mp4"></video></div>';

$(function() {
	 _V_.options.flash.swf = "/js/video-js.swf";
	/*$('.peMopho').mouseenter(function(){
		playerID = playerIDtext + playerNum;
		$(this).append(playerHTMLbegin + playerID + playerHTMLend);
		playerNum++;
		//$('.videoPreviewDiv').offset({top:$(this).offset().top - 5, left:$(this).offset().left - 5});
		$('#' + playerID + ' source').attr('src', $(this).attr('video-file'));
		$('#' + playerID).parents('.videoPreviewDiv').fadeIn('slow');
		_V_(playerID).ready(function(){
			var myPlayer = this;
			//myPlayer.currentTime(0);
			myPlayer.play();
		});
		var myPlayer = _V_(playerID);
		//myPlayer.currentTime(0);
		myPlayer.play();
	}).mouseleave(function()
	{
		$('#' + playerID).parents('.videoPreviewDiv').remove();
	});*/
	
	$('#all_pages').on('mouseenter', '.peMopho', function(){
		playerID = playerIDtext + playerNum;
		$(this).append(playerHTMLbegin + playerID + playerHTMLend);
		playerNum++;
		//$('.videoPreviewDiv').offset({top:$(this).offset().top - 5, left:$(this).offset().left - 5});
		$('#' + playerID + ' source').attr('src', $(this).attr('video-file'));
		$('#' + playerID).parents('.videoPreviewDiv').fadeIn('slow');
		_V_(playerID).ready(function(){
			var myPlayer = this;
			//myPlayer.currentTime(0);
			if ( $(playerID + '_html5_api').readyState === 4 ) {
				myPlayer.play();
			}			
		});
		var myPlayer = _V_(playerID);
		//myPlayer.currentTime(0);
		myPlayer.play();
	})
	$('#all_pages').on('mouseleave', '.peMopho', function()
	{
		$('#' + playerID).parents('.videoPreviewDiv').remove();
	});
});

/*var playerHTMLbegin = '<div class = "videoPreviewDiv"><div id = "';
var playerHTMLend = '" ></div></div>';
var serveURL = 'http://214.joyhost.ru/';

$(function() {
	$('.peMopho').mouseenter(function(){
		playerID = playerIDtext + playerNum;
		$(this).append(playerHTMLbegin + playerID + playerHTMLend);
		playerNum++;
		$('#' + playerID).parents('.videoPreviewDiv').fadeIn('slow');
		jwplayer(playerID).setup({
			file: serveURL + $(this).attr('video-file'),
			width: "124",
			height: "80",
			image: serveURL + $(this).find('img').attr('src'),
		  });
		 jwplayer(playerID).onReady(function() { jwplayer(playerID).play(); console.log(playerID);});
	}).mouseleave(function()
	{
		jwplayer(playerID).remove();
		$('#' + playerID).parents('.videoPreviewDiv').remove();
	});
});*/